import { _decorator, Component, EventTouch, Node, systemEvent, SystemEvent ,Input, input} from 'cc';
import { gameManger } from '../framework/gameManger';
const { ccclass, property } = _decorator;

@ccclass('UIMain')
export class UIMain extends Component {

    @property
    public speed =1
    @property(Node)
    playerPlane: Node = null;
    @property(gameManger)
    public gameManger: gameManger = null

    start() {
        // 绑定手指触摸事件
        this.node.on(Input.EventType.TOUCH_MOVE, this._onTouchMove, this)
        // 手指点击
        this.node.on(Input.EventType.TOUCH_START, this._onTouchStart, this)
        // 手指离开
        this.node.on(Input.EventType.TOUCH_END, this._onTouchEnd, this)
    }

    // update(deltaTime: number) {
        
    // }

    _onTouchStart(event: EventTouch) {
        this.gameManger.isShoot(true);
    }

    _onTouchMove(event: EventTouch) {
        const delta = event.getDelta()
        let pos = this.playerPlane.position
        // 设置飞机移动的位置
        this.playerPlane.setPosition(pos.x + 0.01 * this.speed * delta.x, pos.y, pos.z - 0.01 * this.speed * delta.y)
    }
    _onTouchEnd(event: EventTouch) {
        this.gameManger.isShoot(false);
    }
}


